package com.beyond.pm.nav

import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import com.beyond.common.constant.APPEARANCE_AND_STYLE
import com.beyond.common.constant.HOME_ROUTE
import com.beyond.common.constant.LANGUAGE_SWITCH
import com.beyond.common.constant.LOGIN_ROUTE
import com.beyond.common.constant.SYSTEM_SETTING_ROUTE
import com.beyond.common.constant.TEST_ROUTE
import com.beyond.common.constant.VERSIONS_AND_UPDATES
import com.beyond.pm.local.LocalNavController
import com.beyond.pm.ui.home.HomeScreen
import com.beyond.pm.ui.login.LoginScreen
import com.beyond.pm.ui.setting.system.SystemSettingScreen
import com.beyond.pm.ui.setting.system.style.AppStyleScreen
import com.beyond.pm.ui.setting.system.language.LanguageScreen
import com.beyond.pm.ui.test.TestPage

/**
 * @author chen
 * @time 2023/6/14 17:31
 * @name ProjectManage
 * @class describe
 */
@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun AppNavHost(isLogin: Boolean) {
    val keyboardController = LocalSoftwareKeyboardController.current
    NavHost(
        modifier = Modifier
            .fillMaxSize()
            .pointerInput(Unit) {
                detectTapGestures(
                    onPress = {
                        keyboardController?.hide()
                    }
                )
            },
        navController = LocalNavController.current,
        startDestination = if (isLogin) HOME_ROUTE else LOGIN_ROUTE
    ) {
        composable(route = LOGIN_ROUTE) {
            LoginScreen()
        }
        composable(route = HOME_ROUTE) {
            HomeScreen()
        }
        composable(route = TEST_ROUTE) {
            TestPage()
        }
        composable(route = SYSTEM_SETTING_ROUTE) {
            SystemSettingScreen()
        }
        composable(route = APPEARANCE_AND_STYLE) {
            AppStyleScreen()
        }
        composable(route = VERSIONS_AND_UPDATES) {
            TestPage()
        }
        composable(route = LANGUAGE_SWITCH) {
            LanguageScreen()
        }
    }
}